package slerp;

/**
 *
 * @author Pasta
 */
public class Gravity {
    private double accelerarion, upvardsVelocity = 0, fallingSpeed = 0;
    private boolean isFalling;
    HerpEngineTime timer;
    public Gravity(double acc) {
        accelerarion = acc;
        timer = new HerpEngineTime();
    }
    public void startFalling() {
        isFalling = true;
        timer.start();
    }
    public void stopFalling() {
        upvardsVelocity = 0;
        isFalling = false;
        fallingSpeed = 0;
        timer.pause();
        timer.reset();
    }
    public double getFallingSpeed() {
        double delta = timer.getDeltaTime() / Math.pow(10, 9);
        fallingSpeed += accelerarion * delta;
        if(isFalling) {
            return fallingSpeed - (upvardsVelocity * delta) ;
        } else {
            return 0;
        }
    }
    public void setUpvardsVelocity(double up) {
        this.upvardsVelocity = up;
    }
    public boolean isFaling() {
        return isFalling;
    }
}
